#ifndef CUSTOMTABLEWIDGETITEM_H
#define CUSTOMTABLEWIDGETITEM_H

#include <QTableWidgetItem>

class CustomTableWidgetItem : public QTableWidgetItem {
public:
    CustomTableWidgetItem(const QString &text) : QTableWidgetItem(text) {}
    CustomTableWidgetItem(int value) : QTableWidgetItem(QString::number(value)) {}

    bool operator<(const QTableWidgetItem &other) const override {
        bool ok1, ok2;
        double value1 = text().toDouble(&ok1);
        double value2 = other.text().toDouble(&ok2);

        if (ok1 && ok2) { // 都是数字
            return value1 < value2;
        }
        return QString::compare(text(), other.text()) < 0; // 字符串比较
    }
};

#endif // CUSTOMTABLEWIDGETITEM_H
